package cn.m3a1.task;

import cn.m3a1.dao.UserDao;
import cn.m3a1.model.Absentnote;
import cn.m3a1.model.Tclass;
import cn.m3a1.model.User;
import com.iceking.dynamicweb.FrmkView;
import com.iceking.dynamicweb.GlobalUtils;
import com.iceking.dynamicweb.Pagination;
import com.iceking.dynamicweb.TaskProcessor;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 * @author wyj
 * @date 2019/6/5
 * @time 下午3:39
 */
public class MyleaveTask extends TaskProcessor {
    private User loginUser;
    public Boolean panduan(){
        loginUser = (User) getSession().getAttribute("loginUser");
        if (loginUser==null){
            return false;
        }

        int type=loginUser.getType();

        if (type!=1){
            return false;
        }
        return  true;
    }
    /**
     * 班级管理首页
     * @throws Exception
     */
    public void home() throws  Exception{
        if (!panduan()){
            return;
        }
        FrmkView frmkView;
        UserDao userDao=new UserDao();

        int id=loginUser.getId();
            //判断是否是超级管理员
            frmkView=new FrmkView("myleave.html");
            //查询所有班级信息
            getDBConn().startTransaction();
            Pagination<Absentnote> pg = new Pagination<>();
            pg.appendWhere("where studentid=?",id);
            getDBConn().select(Absentnote.class, pg);

            List list = pg.getRows();

            getDBConn().stopTransaction();

            frmkView.addData("members",list);
            frmkView.addData("loginUser",loginUser);



        toFreemarker(frmkView);
    }

    /**
     * 班级管理首页
     * @throws Exception
     */
    public void print() throws  Exception{
        if (!panduan()){
            return;
        }
        FrmkView frmkView;


        //判断是否是超级管理员
        frmkView=new FrmkView("Printing.html");
        int id = getParamInt("id");
        //查询所有班级信息
        getDBConn().startTransaction();
        Pagination<Absentnote> pg = new Pagination<>();
        pg.appendWhere("where id=?",id);
        getDBConn().select(Absentnote.class, pg);

         Absentnote absentnote = pg.getFirstResult();

        getDBConn().stopTransaction();

        frmkView.addData("absentnote",absentnote);
        frmkView.addData("loginUser",loginUser);



        toFreemarker(frmkView);
    }
}
